package mypackage;

//import java.awt.FlowLayout;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.*;
import javax.swing.border.TitledBorder;
public class MyJFrame extends JFrame implements ActionListener, ItemListener{
	JLabel l1=new JLabel("Label 1");
	JLabel l2=new JLabel("Label 2");
	JLabel l3=new JLabel("Label 3");
	JLabel l4=new JLabel("Label 4 Laybel 4....");
	JLabel l5=new JLabel("Label 5");
	JLabel l6=new JLabel("Label 6 ...");
	JPanel pGrid,p1,p2,p3,p4;
	JCheckBox cb1,cb2;
		
	JButton b2=new JButton("Press");JButton b3=new JButton("Press");JButton b4=new JButton("Press");JButton b5=new JButton("Press");
	JFileChooser jfc=new JFileChooser(":C:/Users/tanhlee/workspace");
	JButton b1=new JButton("Press");
	public MyJFrame(String title){
		super(title);	
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setSize(300,400);
		this.setVisible(true);
		this.setResizable(false);
		this.setBounds(50,50, 500, 500);
		TitledBorder pname=new TitledBorder("Function");
		cb1=new JCheckBox("option 1");
		cb2=new JCheckBox("option 2");
		cb1.addItemListener(this);
		cb2.addItemListener(this);
		b1.addActionListener(this);
		l1.setToolTipText("Day la label 1");
		p1=new JPanel();
		p1.setBackground(Color.gray);
		p1.setLayout(new FlowLayout());
		p1.add(l1);
		p1.add(b1);
		p2=new JPanel();
		p2.setBackground(Color.magenta);
		GridLayout grid1=new GridLayout(2,2);
		p2.setLayout(grid1);
		p2.setBorder(pname);
		p2.add(cb1);
		p2.add(cb2);
		p2.add(b4);
		p2.add(b5);
		GridLayout grid=new GridLayout(2,3);
		this.setLayout(grid);
		this.add(p1);
		this.add(p2);
		this.add(l3);
		this.add(l4);
		this.add(l5);
		this.add(l6);
	
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==b1){
			String taikhoan=l1.getText().toString();
			JOptionPane.showMessageDialog(null, "tai khoan la: "+taikhoan);
			/* neu truiong hop la TextPasswordField
			 * char[] c=l1.getPassword();
			 * String matkhau=new String(c);
			 */
		}
	}
	public void itemStateChanged(ItemEvent ae){
		if(ae.getItemSelectable()==cb1){
			JOptionPane.showMessageDialog(null, "chon checkbox 1 roi kia");
		}
	}
}
